home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / CmplxHESS.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  3KB  |  145 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "CmplxHESS.h"
  32. #include "f77-fcn.h"
  33. #include "lo-error.h"
  34. #include "mx-inlines.cc"
  35.  
  36. extern "C"
  37. {
  38.   int F77_FCN (zgebal, ZGEBAL) (const char*, const int&, Complex*,
  39.                 const int&, int&, int&, double*, int&,
  40.                 long, long);
  41.  
  42.   int F77_FCN (zgehrd, ZGEHRD) (const int&, const int&, const int&,
  43.                 Complex*, const int&, Complex*,
  44.                 Complex*, const int&, int&, long,
  45.                 long);
  46.  
  47.   int F77_FCN (zunghr, ZUNGHR) (const int&, const int&, const int&,
  48.                 Complex*, const int&, Complex*,
  49.                 Complex*, const int&, int&, long, long);
  50.  
  51.   int F77_FCN (zgebak, ZGEBAK) (const char*, const char*, const int&,
  52.                 const int&, const int&, double*,
  53.                 const int&, Complex*, const int&,
  54.                 int&, long, long);
  55. }
  56.  
  57. int
  58. ComplexHESS::init (const ComplexMatrix& a)
  59. {
  60.   int a_nr = a.rows ();
  61.   int a_nc = a.cols ();
  62.  
  63.   if (a_nr != a_nc)
  64.     {
  65.       (*current_liboctave_error_handler)
  66.     ("ComplexHESS requires square matrix");
  67.       return -1;
  68.     }
  69.  
  70.   char job = 'N';
  71.   char side = 'R';
  72.  
  73.   int n = a_nc;
  74.   int lwork = 32 * n;
  75.   int info;
  76.   int ilo;
  77.   int ihi;
  78.  
  79.   hess_mat = a;
  80.   Complex *h = hess_mat.fortran_vec ();
  81.  
  82.   Array<double> scale (n);
  83.   double *pscale = scale.fortran_vec ();
  84.  
  85.   F77_XFCN (zgebal, ZGEBAL, (&job, n, h, n, ilo, ihi, pscale, info,
  86.                  1L, 1L));
  87.  
  88.   if (f77_exception_encountered)
  89.     (*current_liboctave_error_handler) ("unrecoverable error in zgebal");
  90.   else
  91.     {
  92.       Array<Complex> tau (n-1);
  93.       Complex *ptau = tau.fortran_vec ();
  94.  
  95.       Array<Complex> work (lwork);
  96.       Complex *pwork = work.fortran_vec ();
  97.  
  98.       F77_XFCN (zgehrd, ZGEHRD, (n, ilo, ihi, h, n, ptau, pwork, lwork,
  99.                  info, 1L, 1L));
  100.  
  101.       if (f77_exception_encountered)
  102.     (*current_liboctave_error_handler) ("unrecoverable error in zgehrd");
  103.       else
  104.     {
  105.       unitary_hess_mat = hess_mat;
  106.       Complex *z = unitary_hess_mat.fortran_vec ();
  107.  
  108.       F77_XFCN (zunghr, ZUNGHR, (n, ilo, ihi, z, n, ptau, pwork,
  109.                      lwork, info, 1L, 1L));
  110.  
  111.       if (f77_exception_encountered)
  112.         (*current_liboctave_error_handler)
  113.           ("unrecoverable error in zunghr");
  114.       else
  115.         {
  116.           F77_XFCN (zgebak, ZGEBAK, (&job, &side, n, ilo, ihi,
  117.                      pscale, n, z, n, info, 1L, 1L));
  118.  
  119.           if (f77_exception_encountered)
  120.         (*current_liboctave_error_handler)
  121.           ("unrecoverable error in zgebak");
  122.           else
  123.         {
  124.           // If someone thinks of a more graceful way of
  125.           // doing this (or faster for that matter :-)),
  126.           // please let me know!
  127.  
  128.           if (n > 2)
  129.             for (int j = 0; j < a_nc; j++)
  130.               for (int i = j+2; i < a_nr; i++)
  131.             hess_mat.elem (i, j) = 0;
  132.         }
  133.         }
  134.     }
  135.     }
  136.  
  137.   return info;
  138. }
  139.  
  140. /*
  141. ;;; Local Variables: ***
  142. ;;; mode: C++ ***
  143. ;;; End: ***
  144. */
  145.